package br.ita.battlefarm.core;


public class Position {
	public int x;
	public int y;
	public boolean isHit = false;

	public Position() {
		this(0, 0);
	}

	public Position(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public void rotateLeft(Position pole) {
		if(this != pole){
			subtract(pole);
			rotateLeftByOrigin();
			add(pole);
		}
	}

	public void rotateRight(Position pole) {
		if(this != pole){
			subtract(pole);
			rotateRightByOrigin();
			add(pole);
		}
	}

	private void rotateLeftByOrigin() {
		int x_old = x;
		x = -y;
		y = x_old;
	}

	private void rotateRightByOrigin() {
		int x_old = x;
		x = y;
		y = -x_old;
	}

	private void add(Position pole) {
		x = x + pole.x;
		y = y + pole.y;
	}

	private void subtract(Position p) {
		x = x - p.x;
		y = y - p.y;
	}

	@Override
	public String toString() {
		return "(" + x + "," + y + ")";
	}

	@Override
	//Two positions are equal IF THEY HAVE THE SAME COORDINATES
	public boolean equals(Object o) {
		if (o instanceof Position) {
			Position p = (Position) o;
			return p.x == this.x && p.y == this.y;
		}
		return super.equals(o);
	}

	public boolean isHit() {
		return isHit;
	}
}
